<?php
namespace app\admin\controller;

use think\facade\View;
use app\common\business\Goods as goodsBusi;
class Goods extends AdminBase
{
	public function index(){
		$data = [];
		$title = input('param.title','','trim');
		$time = input('param.time','','trim');
		if(!empty($title)){
			$data['title'] = $title;
		}
		if(!empty($time)){
			$data['create_time'] = explode(' - ', $time);
			//echo '<pre>';print_r($data);exit;
		}
		
		$goods = (new goodsBusi())->getLists($data,5);
		//dump($goods);
		return View("",[
			'goods'=>$goods,
			'title'=>$title,
			'time'=>$time,
		]);	
	}

	public function add(){
		return View();
	}

	// 添加商品
	public function save(){
		//判断是否为post请求
		if(!$this->request->isPost()){
			return show(config('status.error'),'参数不合法');
		}

		$data = input('param.');
		//halt($data);
		//数据处理
		$data['category_path_id'] = $data['category_id'];
		$arr = explode(",", $data['category_path_id']);
		$data['category_id'] =  end($arr);
		try{
			$res = (new goodsBusi())->insertData($data);
		}catch(\Exception $e){
			return show(config('status.error'),$e->getMessage());
		}
		if(!$res){
			return show(config('status.error'),'商品新增失败');
		}

		return show(config('status.success'),'商品新增ok');
	}

}